import router from '@/router'

import { Module } from 'vuex'
import { IRootState } from '../type'
import { UserGetAll, RoleGetAll, TenantGetAll } from '@/service/main/main'
export interface IRoutePath {
  name: string
  userData: any[]
  roleData: any[]
  tenantData: any[]
}

const settingState: Module<IRoutePath, IRootState> = {
  namespaced: true, //命名空间
  state: () => {
    return {
      name: '',
      userData: [],
      roleData: [],
      tenantData: [],
    }
  },
  mutations: {
    changePath(state, name: string) {
      state.name = name
    },
    changeUserData(state, userData: any[]) {
      state.userData = userData
    },
    changeRoleData(state, roleData: any[]) {
      state.roleData = roleData
    },
    changetenantData(state, tenantData: any[]) {
      state.tenantData = tenantData
    },
  },
  getters: {},
  actions: {
    changePathAtion({ commit }, payload) {
      const nameRoute = payload
      commit('changePath', nameRoute)
    },
    async goUserData({ commit }, payload) {
      const GetAllRes = await UserGetAll(payload)
      const userData = GetAllRes.result
      // console.log(userData)
      commit('changeUserData', userData)
    },
    async goRoleData({ commit }, payload) {
      const GetAllRes = await RoleGetAll(payload)
      const roleData = GetAllRes.result
      commit('changeRoleData', roleData)
    },
    async goTenantData({ commit }, payload) {
      const GetAllRes = await TenantGetAll(payload)

      const tenantData = GetAllRes.result
      commit('changetenantData', tenantData)
    },
  },
}
export default settingState
